package com.server.modules.api.service.impl;
import com.server.common.service.CrudService;
import com.server.common.utils.StringUtils;
import com.server.modules.api.dao.FriendsAPIDao;
import com.server.modules.api.service.IFriendsService;
import com.server.modules.api.vo.FriendQueryVO;
import com.server.modules.sys.dao.UserDao;
import com.server.modules.sys.dao.friends.FriendsDao;
import com.server.modules.sys.dao.member.MemberDao;
import com.server.modules.sys.entity.User;
import com.server.modules.sys.entity.friends.Friends;
import com.server.modules.sys.entity.member.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Created by Administrator on 2016/9/2.
 */
@Service
public class FriendsServiceImpl extends CrudService<FriendsDao, Friends> implements IFriendsService {
    @Autowired
    protected MemberDao memberDao;
    @Autowired
    protected FriendsAPIDao friendsAPIDao;

    @Autowired
    protected UserDao userDao;
    @Override
    @Transactional(readOnly = false)
    public void addFriends(Friends friends) {
        super.save(friends);
    }

    @Override
    @Transactional(readOnly = false)
    public void delFriends(Friends friends) {
        friendsAPIDao.delFriend(friends);
    }

    @Override
    public boolean checkFriends(Friends friends) {
       List<Friends> friendses   =   friendsAPIDao.getFriend(friends);
        if (friendses != null && friendses.size()>0)
            return true;
        else return false;
    }
    @Override
    public String getUserHxUserName(String id){
        Member member =  memberDao.get(id);
        return member.getHxUsername();
    }
    @Override
    public  List<FriendQueryVO>  getFriendsList(Member member) {
        List<FriendQueryVO> list = friendsAPIDao.getAllFriends(member);
        return list;
    }

}
